<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .adver {
            width: 300px;
            /* height: 400px; */
            background-color: aquamarine;
            position: fixed;
            right: 5px;
            bottom: 5px;
            /* display: none; */
            /* display: block; */
        }

        .adver-header {
            overflow: hidden;
            line-height: 20px;
            font-size: 13px;
            padding: 0 5px;
        }

        .adver-header .adver-title {
            float: left;
        }

        .adver-header .adver-close {
            float: right;
        }

        .adver-main img {
            width: 100%;
        }
    </style>
</head>

<body>
    <!-- <div class="adver">
        <div class="adver-header">
            <div class="adver-title">距离广告关闭还有10秒</div>
            <div class="adver-close">X</div>
        </div>
        <div class="adver-main">
            <img src="../images/bzsc-dgbhz-300-250-7-5.gif" alt="">
        </div>
    </div> -->
</body>
<script>
   /* 
     
   
   
   */


    /*  小广告
         页面加载完毕 等待5s 小广告生成
         倒计时10s后关闭小广告
         重复1-2
         点击关闭按钮 => 清除小广告 => 重复 1 2 3 


        阻止事件冒泡: 

        click: adver-close -> adver-header -> adver

 
     */

    var body = document.querySelector("body");

    showAdver();

    function showAdver() {
        var timer = setTimeout(function () {

            var count = 60;

            var adver = document.createElement("div");
            adver.className = "adver";
            adver.onclick = function(){
                location.href = "https://www.baidu.com"
            }

            // adverHeader
            var adverHeader = document.createElement("div");
            adverHeader.className = "adver-header";
            adver.appendChild(adverHeader);

            var adverTitle = document.createElement("div");
            adverTitle.className = "adver-title";
            adverTitle.textContent = `距离广告关闭还有${count}秒`;
            adverHeader.appendChild(adverTitle);

            var adverClose = document.createElement("div");
            adverClose.className = "adver-close";
            adverClose.textContent = `X`;
            adverHeader.appendChild(adverClose);

            adverClose.onclick = function(e){
                clearTimeout(timer);
                clearInterval(timer1);
                adver.remove();
                showAdver();

                if(e.stopPropagation){
                    e.stopPropagation()
                }else{
                    e.cancelBubble = true;
                }
            }

            // adverMain
            var adverMain = document.createElement("div");
            adverMain.className = "adver-main";
            adver.appendChild(adverMain);


            var img = document.createElement("img");
            img.src = "../images/bzsc-dgbhz-300-250-7-5.gif";
            adverMain.appendChild(img);

            document.body.appendChild(adver);


            var timer1 = setInterval(function () {
                count--;
                adverTitle.innerText = `距离广告关闭还有${count}秒`;

                if (count == 0) {
                    clearInterval(timer1);
                    adver.remove();

                    showAdver();
                }
            }, 1000);




        },5000);
    }










</script>

</html>